#region [file: EstadoDAL.cs, author: Lucas Bittencourt]
// File:    EstadoDAL.cs
// Author:  Lucas Bittencourt
// Created: terça-feira, 25 de outubro de 2011 09:26:29
// Purpose: Defines dao implementation class for class Estado
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IEstadoDAL interface
   /// </summary>
   public class EstadoDAL : NHibernateDALBase,  IEstadoDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Estado
      /// </summary>     
      public List<Estado> GetEstadoList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Estado)));
      }
      
      /// <summary>
      /// Get the instances of Estado from index firstResult to index maxResult
      /// </summary>
      public List<Estado> GetEstadoList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Estado), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Estado according its primary key instance.
      /// </summary>
      public Estado Load(EstadoPK estadoPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "EstIdEstado" };
         object[] values = new object[] { estadoPK.EstIdEstado };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Estado), cs);
         return (((list != null) && (list.Count > 0)) ? (Estado)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Estado according its example instance.
      /// </summary>
      public List<Estado> QueryByExample(Estado estado)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Estado), estado));
      }

      /// <summary>
      /// Query the instances of Estado according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Estado> QueryByExample(Estado estado, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Estado), estado, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Estado
      /// </summary>
      public void Insert(Estado estadoObject)
      {
         base.Save(estadoObject);
      }
      
      /// <summary>
      /// Update the instances of Estado
      /// </summary>
      public void Update(Estado estadoObject)
      {
         base.Update(estadoObject);
      }
      
      /// <summary>
      /// Delete the instances of Estado
      /// </summary>
      public void Delete(Estado estadoObject)
      {
         base.Delete(estadoObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Estado according to its attribute estSgEstado
      /// </summary>
      public List<Estado> FindByEstSgEstado(string estSgEstado) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstSgEstado", estSgEstado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs));
      }
      
      /// <summary>
      /// Find the instances of Estado according to its attribute estSgEstado, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Estado> FindByEstSgEstado(string estSgEstado, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstSgEstado", estSgEstado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Estado according to its attribute estNmEstado
      /// </summary>
      public List<Estado> FindByEstNmEstado(string estNmEstado) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstNmEstado", estNmEstado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs));
      }
      
      /// <summary>
      /// Find the instances of Estado according to its attribute estNmEstado, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Estado> FindByEstNmEstado(string estNmEstado, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstNmEstado", estNmEstado));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Estado according to its attribute estCdIbge
      /// </summary>
      public List<Estado> FindByEstCdIbge(decimal estCdIbge) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstCdIbge", estCdIbge));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs));
      }
      
      /// <summary>
      /// Find the instances of Estado according to its attribute estCdIbge, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Estado> FindByEstCdIbge(decimal estCdIbge, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EstCdIbge", estCdIbge));
         return ConvertToGenericList(base.FindByCriterions(typeof(Estado), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Estado> ConvertToGenericList(IList estados)
      {
         List<Estado> estadoList = new List<Estado>();
         foreach (Estado estado in estados)
         {
             estadoList.Add(estado);
         }
         return estadoList;
      }      
   }
}